<?php
namespace Admin\Model;
use Common\Model\CommonModel;
class FragModel extends  CommonModel{
	
	//自动验证
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('title', 'require', '名称不能为空！', 1, 'regex', 3),
			array('pos', 'require', '调用标签不能为空！', 1, 'regex', 3),
			array('pos', '', '调用标签已经存在！', 0 ,'unique', CommonModel:: MODEL_BOTH   ),
			array('thumb', 'require', '图片不能为空！' ),
			array('content', 'require', '内容不能为空！'),
		
		
	);
	
	/**
	 * 后台有更新/编辑则删除缓存
	 * @param type $data
	 */
	public function _before_write() {
		parent::_before_write();
		$this->data_cache();
	}
	public function _after_insert() {
		parent::_after_insert();
		$this->data_cache();
	}
	//删除操作时删除缓存
	public function _after_delete() {
		parent::_after_delete();
		$this->data_cache();
	}
	public function data_cache(){
		
	$data=$this->select();
		
		
	
		foreach ($data as $k=>$v){
				
			$result[$v[pos]]=textarea_br($v[content]);
			
		}
		
		F("Frag",$result);
	}
	
}